home *** CD-ROM | disk | FTP | other *** search
/ SPACE 1 / SPACE - Library 1 - Volume 1.iso / utilitys / 289 / oops.lst < prev    next >
Encoding:
File List  |  1980-01-09  |  13.1 KB  |  620 lines

  1. '
  2. ' OOPS! v1.01 BFH Ascii recovery program by Dave Groves and Dan Rhea
  3. '
  4. ' This program will traverse a disk a sector at a time and optionally allow
  5. ' the sector to be copied to a file on another disk
  6. '
  7. ' 01/09/89 - Added UnTwist and ReTwist. These alter the boot sector to and from
  8. '            a normal and twisted format. Only double sided is supported in
  9. '            this version. The nest will also handle single sided.
  10. '
  11. ' Set up and greet the sucker... er I mean user
  12. '
  13. Cls
  14. Showm
  15. @Nowrap
  16. @Inv
  17. @Zapl(1)
  18. @Zapl(25)
  19. @Cent("OOPS! v1.01 Micro Floppy Recovery Utility - David G. Groves & Dan Rhea",1)
  20. @Nor
  21. @Cent("OOPS! v1.01 (c) 1988, 1989 by David G. Groves & Dan Rhea",12)
  22. @Cent("This program may be copied but may never be sold",13)
  23. @Inv
  24. @Cent("Press any key to continue...",25)
  25. @Nor
  26. Got$=""
  27. While Got$=""
  28.   Got$=Inkey$
  29. Wend
  30. '
  31. ' Initialize a few things...
  32. '
  33. Maxsect%=2
  34. Sector%=0
  35. Ctlz$=Chr$(26)
  36. Cluster%=1
  37. Fspec$="C:\*.*"
  38. Filename$=""
  39. Thefile$=""
  40. Cdrive%=-1
  41. Buffer1$=String$(512,0)
  42. Buffer2$=String$(512,0)
  43. Buflen%=1024
  44. Buff1%=Varptr(Buffer1$)
  45. Buff2%=Varptr(Buffer2$)
  46. Rawb%=0
  47. '
  48. ' Put up the main menu and get the selection
  49. '
  50. @Zapl(12)
  51. @Zapl(13)
  52. @Inv
  53. @Zapl(25)
  54. @Nor
  55. @Cent("Please select one of the following program options...",10)
  56. @Cent("(U)n-Twist a double sided Turtle disk with normal image data on it",12)
  57. @Cent("(R)e-Twist a double sided Turtle disk with Twister image data on it",13)
  58. @Cent("(S)ector to file scan, analyse and copy",14)
  59. @Inv
  60. Kack=False
  61. While Kack=False
  62.   @Cent("(U)n-Twist, (R)e-Twist or (S)ector to file recovery ",25)
  63.   Cmd$=Chr$(Inp(2))
  64.   If Cmd$="U" Or Cmd$="u" Then
  65.     @Untwist
  66.   Else
  67.     If Cmd$="R" Or Cmd$="r" Then
  68.       @Retwist
  69.     Else
  70.       If Cmd$="S" Or Cmd$="s" Then
  71.         Kack=True
  72.       Else
  73.         Print Chr$(7);
  74.       Endif
  75.     Endif
  76.   Endif
  77. Wend
  78. @Zapl(25)
  79. @Nor
  80. For I=10 To 14
  81.   @Zapl(I)
  82. Next I
  83. '
  84. ' Which drive shall we tamper with?
  85. '
  86. Afile=False
  87. While Cdrive%=-1
  88.   @Inv
  89.   @Cent("Enter source drive (A or B ONLY) ",25)
  90.   D$=Chr$(Inp(2))
  91.   If D$="A" Or D$="a" Then
  92.     Cdrive%=0
  93.   Else
  94.     If D$="B" Or D$="b" Then
  95.       Cdrive%=1
  96.     Endif
  97.   Endif
  98. Wend
  99. @Zapl(25)
  100. @Nor
  101. '
  102. ' Grab a sector from the selected disk and display it
  103. '
  104. @Wrap
  105. While Rawb%=0
  106.   @Nowrap
  107.   If Sector%>=Maxsect% Then
  108.     Sector%=Maxsect%
  109.   Endif
  110.   Rawb%=Bios(4,2,L:Buff1%,Cluster%,Sector%,Cdrive%)
  111.   '
  112.   ' If this is the boot sector then get the max number of them on the disk
  113.   '
  114.   If Sector%=0 Then
  115.     Max1%=(Peek(Buff1%+&H14) And &HFF)*256
  116.     Maxsect%=Peek(Buff1%+&H13)+Max1%-1
  117.   Endif
  118.   @Inv
  119.   @Zapl(25)
  120.   @Showsect
  121.   @Inv
  122.   @Cent("Return/Enter to continue, Esc to command menu...",25)
  123.   @Nor
  124.   @Zapl(6)
  125.   '
  126.   ' Check for and announce an EOF if we find one in this sector
  127.   '
  128.   If Instr(Buffer1$,Ctlz$) Then
  129.     @Cent("** EOF Detected in this sector **",6)
  130.     Print At(0,0);Chr$(7);
  131.   Endif
  132.   Ok=False
  133.   While Ok=False
  134.     '
  135.     ' Pause here just to be irritating
  136.     '
  137.     Got$=""
  138.     While Got$=""
  139.       Got$=Inkey$
  140.     Wend
  141.     '
  142.     ' If we get an Escape put up the command prompt
  143.     '
  144.     If Got$=Chr$(27)
  145.       Ok=True
  146.       If Afile=False
  147.         @Inv
  148.         @Cent("E(X)it, (F)ile, (B)ack a sector, (G)oto sector Or (C)ontinue",25)
  149.         I$=Chr$(Inp(2))
  150.         @Nor
  151.         '
  152.         ' Check for Quit
  153.         '
  154.         If I$="X" Or I$="x" Then
  155.           Cls
  156.           @Wrap
  157.           Edit
  158.         Else
  159.           '
  160.           ' Check for file create
  161.           '
  162.           If I$="F" Or I$="f" Then
  163.             @Newfile
  164.           Else
  165.             '
  166.             ' Check for move back one sector
  167.             '
  168.             If I$="B" Or I$="b" Then
  169.               Sector%=Sector%-Cluster%
  170.               If Sector%<=0 Then
  171.                 Sector%=-1
  172.               Else
  173.                 Sector%=Sector%-1
  174.               Endif
  175.             Else
  176.               '
  177.               ' Check for a GOTO sector
  178.               '
  179.               If I$="G" Or I$="g" Then
  180.                 @Zapl(6)
  181.                 @Cent2("Enter desired sector ?  ",6)
  182.                 Print "Enter desired sector ";
  183.                 Input Sec%
  184.                 If Sec%>Maxsect% Then
  185.                   Sec%=Maxsect%
  186.                 Endif
  187.                 Sector%=Sec%-1
  188.                 @Zapl(6)
  189.               Endif
  190.             Endif
  191.           Endif
  192.         Endif
  193.         @Inv
  194.         @Cent("Return/Enter to continue, Esc to command menu...",25)
  195.         @Nor
  196.       Else
  197.         '
  198.         ' Display the "processing file" command prompt
  199.         '
  200.         @Inv
  201.         @Cent("(E)nd of File, or (C)ontinue",25)
  202.         I$=Chr$(Inp(2))
  203.         @Nor
  204.         '
  205.         ' Check for end of this file
  206.         '
  207.         If I$="E" Or I$="e" Then
  208.           @Endfile
  209.           Afile=False
  210.         Endif
  211.         @Inv
  212.         @Cent("Return/Enter to continue, Esc for command menu...",25)
  213.         @Nor
  214.       Endif
  215.     Endif
  216.     '
  217.     ' See if we just got a vanillia Return
  218.     '
  219.     If Got$=Chr$(13)
  220.       Ok=True
  221.     Endif
  222.   Wend
  223.   '
  224.   ' If we have an active file then copy a sector to it
  225.   '
  226.   If Afile=True
  227.     @Addfile
  228.   Endif
  229.   '
  230.   ' Move to next sector and reset buffers
  231.   '
  232.   Sector%=Sector%+Cluster%
  233.   I%=0
  234.   While I%<513
  235.     Poke Buff1%+I%,0
  236.     Poke Buff2%+I%,0
  237.     Inc I%
  238.   Wend
  239. Wend
  240. '
  241. ' If a file is still open then close it
  242. '
  243. If Afile=True Then
  244.   Close #1
  245. Endif
  246. '
  247. ' Take off eh...
  248. '
  249. Cls
  250. @Wrap
  251. Edit
  252. ' -----------------------------------------------------------------------------
  253. ' ShowSect - Show the sector just read
  254. '
  255. Procedure Showsect
  256.   @Nor
  257.   @Zapl(9)
  258.   @Wrap
  259.   @Curs(1,9)
  260.   '
  261.   ' Show some status info
  262.   '
  263.   Print "Sector number ";Sector%;" RWABS Status ";Rawb%;" Sectors ";Maxsect%;
  264.   '
  265.   ' Move everything from the working buffer to the display buffer but rotate any
  266.   ' unprintible characters to a "."
  267.   '
  268.   C%=0
  269.   While C%<512
  270.     S%=Peek(Buff1%+C%)
  271.     If S%<32 Or S%>126
  272.       If S%<129
  273.         S%=46
  274.       Endif
  275.     Endif
  276.     Poke Buff2%+C%,S%
  277.     Inc C%
  278.   Wend
  279.   '
  280.   ' Display the display buffer
  281.   '
  282.   @Curs(1,10)
  283.   For P%=1 To 80
  284.     Print "_";
  285.   Next P%
  286.   Print Buffer2$
  287.   For P%=1 To 80
  288.     Print "_";
  289.   Next P%
  290.   @Nowrap
  291. Return
  292. ' -----------------------------------------------------------------------------
  293. ' NewFile - Get the name of the newfile and open it.
  294. '
  295. Procedure Newfile
  296.   Fileselect Fspec$,Filename$,Thefile$
  297.   If Thefile$="" Then
  298.     Afile=False
  299.     Sector%=Sector%-Cluster%
  300.   Else
  301.     Open "O",#1,Thefile$
  302.     Afile=True
  303.   Endif
  304. Return
  305. ' -----------------------------------------------------------------------------
  306. ' AddFile - Add a sector to the open file.
  307. '
  308. Procedure Addfile
  309.   @Inv
  310.   @Cent("Writing current sector to file...",25)
  311.   Bput #1,Buff1%,512
  312.   @Nor
  313.   @Curs(1,20)
  314.   Print "Added 512 bytes to ";Thefile$;" (last sector shown)"
  315. Return
  316. ' -----------------------------------------------------------------------------
  317. ' EndFile - End the current file
  318. '
  319. Procedure Endfile
  320.   Close #1
  321.   Sector%=Sector%-Cluster%
  322.   @Zapl(20)
  323. Return
  324. ' -----------------------------------------------------------------------------
  325. '
  326. ' Untwist - Convert a disk with a Twisted boot sector but normal data to normal
  327. '
  328. Procedure Untwist
  329.   '
  330.   ' Set up a loop so we can do a whole heap a disks
  331.   '
  332.   Imdone=False
  333.   While Imdone=False
  334.     '
  335.     ' Setup the screen for displau
  336.     '
  337.     @Inv
  338.     @Zapl(25)
  339.     @Nor
  340.     For I=10 To 14
  341.       @Zapl(I)
  342.     Next I
  343.     Sector%=0
  344.     Cdrive%=-1
  345.     '
  346.     ' Find out which drive we will be dealing with
  347.     '
  348.     While Cdrive%=-1
  349.       @Inv
  350.       @Cent("Enter source drive (A or B ONLY) ",25)
  351.       D$=Chr$(Inp(2))
  352.       If D$="A" Or D$="a" Then
  353.         Cdrive%=0
  354.       Else
  355.         If D$="B" Or D$="b" Then
  356.           Cdrive%=1
  357.         Endif
  358.       Endif
  359.     Wend
  360.     @Zapl(25)
  361.     @Nor
  362.     '
  363.     ' Get and show the boot sector
  364.     '
  365.     Rawb%=Bios(4,2,L:Buff1%,Cluster%,Sector%,Cdrive%)
  366.     Max1%=(Peek(Buff1%+&H14) And &HFF)*256
  367.     Maxsect%=Peek(Buff1%+&H13)+Max1%-1
  368.     @Showsect
  369.     @Zapl(20)
  370.     @Curs(1,20)
  371.     '
  372.     ' Verify the format of the boot sector
  373.     '
  374.     Print Hex$(Peek(Buff1%+19));" ";Hex$(Peek(Buff1%+20));" ";Hex$(Peek(Buff1%+24));
  375.     If Peek(Buff1%+19)=&H40 And Peek(Buff1%+20)=&H6 And Peek(Buff1%+24)=&HA Then
  376.       '
  377.       ' Modify it to normal format
  378.       '
  379.       Poke Buff1%+19,&HA0
  380.       Poke Buff1%+20,&H5
  381.       Poke Buff1%+24,&H9
  382.       Rawb%=Bios(4,3,L:Buff1%,Cluster%,Sector%,Cdrive%)
  383.       @Showsect
  384.       '
  385.       ' Clear the buffer
  386.       '
  387.       I%=0
  388.       While I%<513
  389.         Poke Buff1%+I%,0
  390.         Poke Buff2%+I%,0
  391.         Inc I%
  392.       Wend
  393.     Else
  394.       '
  395.       ' Argh! This is not Twisted...
  396.       '
  397.       @Inv
  398.       @Cent("Error: Disk does not have a Twister boot sector! Any key to Quit...",25)
  399.       Print Chr$(7);
  400.       While Inkey$=""
  401.       Wend
  402.       '
  403.       ' Bail out
  404.       '
  405.       @Nor
  406.       Cls
  407.       Edit
  408.     Endif
  409.     '
  410.     ' Pass on the good news
  411.     '
  412.     @Inv
  413.     @Cent("Disk is patched. Shall we do another? (Y/N) ",25)
  414.     Cmd$=Chr$(Inp(2))
  415.     @Nor
  416.     '
  417.     ' Fix up the screen for the next victim
  418.     '
  419.     For I=9 To 20
  420.       @Zapl(I)
  421.     Next I
  422.     If Cmd$<>"Y" And Cmd$<>"y" Then
  423.       Imdone=True
  424.     Else
  425.       @Inv
  426.       @Zapl(25)
  427.       @Nor
  428.     Endif
  429.   Wend
  430.   @Nor
  431.   @Cent("Warning! Once the data is recovered from these disks, they MUST be",10)
  432.   @Cent("re-formatted before they can be used again!",11)
  433.   Cls
  434.   Edit
  435. Return
  436. ' -----------------------------------------------------------------------------
  437. '
  438. ' Retwist - Convert a disk with a normal boot sector but Twisted data to Twisted
  439. '
  440. Procedure Retwist
  441.   '
  442.   ' Set up so we can keep processing disks
  443.   '
  444.   Imdone=False
  445.   While Imdone=False
  446.     @Inv
  447.     @Zapl(25)
  448.     @Nor
  449.     For I=10 To 14
  450.       @Zapl(I)
  451.     Next I
  452.     Sector%=0
  453.     '
  454.     ' Find the volenteer
  455.     '
  456.     Cdrive%=-1
  457.     While Cdrive%=-1
  458.       @Inv
  459.       @Cent("Enter source drive (A or B ONLY) ",25)
  460.       D$=Chr$(Inp(2))
  461.       If D$="A" Or D$="a" Then
  462.         Cdrive%=0
  463.       Else
  464.         If D$="B" Or D$="b" Then
  465.           Cdrive%=1
  466.         Endif
  467.       Endif
  468.     Wend
  469.     '
  470.     ' Get the boot sector
  471.     '
  472.     @Zapl(25)
  473.     @Nor
  474.     Rawb%=Bios(4,2,L:Buff1%,Cluster%,Sector%,Cdrive%)
  475.     Max1%=Peek(Buff1%+&H14)*256
  476.     Maxsect%=Peek(Buff1%+&H13)+Max1%-1
  477.     @Showsect
  478.     @Zapl(20)
  479.     @Curs(1,20)
  480.     '
  481.     ' Verify it's normalcy
  482.     '
  483.     Print Hex$(Peek(Buff1%+19));" ";Hex$(Peek(Buff1%+20));" ";Hex$(Peek(Buff1%+24));
  484.     If Peek(Buff1%+19)=&HA0 And Peek(Buff1%+20)=&H5 And Peek(Buff1%+24)=&H9 Then
  485.       '
  486.       ' Modify it to a twisted boot sector
  487.       '
  488.       Poke Buff1%+19,&H40
  489.       Poke Buff1%+20,&H6
  490.       Poke Buff1%+24,&HA
  491.       Rwab%=Bios(4,3,L:Buff1%,Cluster%,Sector%,Cdrive%)
  492.       @Showsect
  493.       '
  494.       ' Clear out the buffers
  495.       '
  496.       I%=0
  497.       While I%<513
  498.         Poke Buff1%+I%,0
  499.         Poke Buff2%+I%,0
  500.         Inc I%
  501.       Wend
  502.     Else
  503.       '
  504.       ' Dis ain't no steenkin normal boot sector
  505.       '
  506.       @Inv
  507.       @Cent("Error: Disk does not have a normal boot sector! Any key to Quit...",25)
  508.       Print Chr$(7);
  509.       While Inkey$=""
  510.       Wend
  511.       '
  512.       ' Like take off dude fer sure
  513.       '
  514.       @Nor
  515.       Cls
  516.       Edit
  517.     Endif
  518.     '
  519.     ' Pass on the joyous news
  520.     '
  521.     @Inv
  522.     @Cent("Disk is patched. Shall we do another? (Y/N) ",25)
  523.     Cmd$=Chr$(Inp(2))
  524.     @Nor
  525.     '
  526.     ' Set up for the next disk
  527.     '
  528.     For I=9 To 20
  529.       @Zapl(I)
  530.     Next I
  531.     If Cmd$<>"Y" And Cmd$<>"y" Then
  532.       Imdone=True
  533.     Else
  534.       @Inv
  535.       @Zapl(25)
  536.       @Nor
  537.     Endif
  538.   Wend
  539.   @Nor
  540.   @Cent("Warning! Once the data is recovered from these disks, they MUST be",10)
  541.   @Cent("re-formatted before they can be used again!",11)
  542.   Cls
  543.   Edit
  544. Return
  545. ' ========================== screen library v1.01 =============================
  546. '
  547. ' Inv - Set Inverse Video
  548. '
  549. Procedure Inv
  550.   Print Chr$(27);"p";
  551. Return
  552. '
  553. ' Nor - Set Normal Video
  554. '
  555. Procedure Nor
  556.   Print Chr$(27);"q";
  557. Return
  558. '
  559. ' Tcol(Col) - Set text color
  560. '
  561. Procedure Tcol(Col)
  562.   If Col>-1 And Col<4 Then
  563.     Print Chr$(27);"b";Chr$(Col);
  564.   Endif
  565. Return
  566. '
  567. ' Bcol(Col) - Set background color
  568. '
  569. Procedure Bcol(Col)
  570.   If Col>-1 And Col<4 Then
  571.     Print Chr$(27);"c";Chr$(Col);
  572.   Endif
  573. Return
  574. '
  575. ' Cent(str) - Center "str" on the current line
  576. '
  577. Procedure Cent(Ctex$,Lin)
  578.   @Zapl(Lin)
  579.   Tlen%=Len(Ctex$)
  580.   Padd%=(80-Tlen%)/2
  581.   Print At(Padd%,Lin);Ctex$;
  582. Return
  583. '
  584. ' Cent2(str) - figure center and set cursor there for normal print
  585. '
  586. Procedure Cent2(Ctex$,Lin)
  587.   @Zapl(Lin)
  588.   Tlen%=Len(Ctex$)
  589.   Padd%=(80-Tlen%)/2
  590.   @Curs(Padd%,Lin)
  591. Return
  592. '
  593. ' Zapl(line) - Blank the line at line indicated
  594. '
  595. Procedure Zapl(Lin)
  596.   For Zapp=1 To 80
  597.     Print At(Zapp,Lin);" ";
  598.   Next Zapp
  599.   @Curs(1,Lin)
  600. Return
  601. '
  602. ' Curs(x,y) - Set cursor to X,Y
  603. '
  604. Procedure Curs(Crx,Cry)
  605.   Print At(Crx,Cry);"";
  606. Return
  607. '
  608. ' Nowrap - turn off end of line wraparound
  609. '
  610. Procedure Nowrap
  611.   Print At(0,0),Chr$(27);"w";
  612. Return
  613. '
  614. ' Wrap - reset eol wraparound
  615. '
  616. Procedure Wrap
  617.   Print At(0,0),Chr$(27);"v";
  618. Return
  619. End
  620.